var fCardId = $("#fCardId").val();
var fDisId = $("#fDisId").val();
var type = $("#type").val();//0为派工单，1为流转卡,2为打印派工单
/*
 * @Description: 预加载
 * @param : 
 */
$(function (){
//	console.log(type)
	var data = {};
	if(type == 0){
		data.fDisId = fDisId;
	}else if(type == 2){
		data.fCardId = fCardId;
	}
//	console.log(data)
	$.ajax({
		url:pathUrl("dispatch/printCard.action"),
		type:'POST',
		dataType:'JSON',
		async : false,
		data:data,
		success:function(data){
//			console.log(data)
			if(data.dataset == "zp"){
				$(".zjANDqj").hide();
				$(".bzzy").show();
			}else if(data.dataset == "sc"){
				$(".zjANDqj").show();
				$(".bzzy").hide();
			}
			var str = "",title;
			data = data.rows;
			str = toUtf8(data.fCode);
			$("#title").text("派工单");
			var key, value;
			for (x in data) {//往span里写值
				key = x;
				value = data[x] == null?"":data[x];
				if(x == 'fStartTime' || x == 'fEndTime' || x == 'fDate'){
					value = dateFormatter(data[x]);
				}
				$("#"+key).text(value);
			}
			if(type == 2){
				$("#fTargetQty").text("");
			}
//			$("#fTargetQty").text("第一次：" + data.fTargetQty);
			
			$("#qrcode").qrcode({
				width: 110,
				height: 110,
				correctLevel : 3,
				text: str
			});
		}
	});
	setTimeout(function(){
		print();
	}, 500);
});

/*
 * @Description: 打印
 * @param :
 */
function print() {
	var canvas=document.getElementsByTagName("canvas")[0];
	var dataURL = canvas.toDataURL("image/png");
	var img = '<img src="'+dataURL+'"></img>';
	$("#qrcode").html(img);
	$(".row").print({
		deferred: $.Deferred().done(function() { 
			window.close(); 
		})//打印完后自动关闭打印页面
	});
}

/*document.onreadystatechange = function () { 
	if(document.readyState == "complete"){ //当页面加载状态为完全结束时进入 
		print();//当页面加载完成后将loading页隐藏
	} 
}*/